
/*********************************************************************
*                                                                    *
* This is the Header file of gen.c a general solver for evolutinary  *
* PDE's which uses standard ODE solvers and Spectral derivatives.    *
*                                                                    *
* Basic definitions include the number of grid points, the number of *
* variables.                                                         *
*                                                                    *
*--------------------------------------------------------------------*
*                                                                    *
* Basic structure is of a field:                                     *
*       struc field_array                                            *
* It holds the array pointing to each gridpoint and the time         *
* There will be also an struc bigvector which points to the whole    *
* array structure (a Union)                                          *
*                                                                    *
*--------------------------------------------------------------------*
*                                                                    *
* Functions in different files:                                      *
*                                                                    *
*    intdat -- provides the initial data (it contains physical parm. *
*    odeint -- integrates ordinary diff. equations dy/dt=F(y,t).     *
*    F      -- routine called by odeint which computes the value of  *
*              the right hand side of the above equation. Here are   *
*              physical parameters.                                  *
*    derivs -- computes derivatives using FFT, the relevant subrouti *
*              nes are contained there.                              *
*    adisco -- Send information to the files                         *
*                                                                    *
*                                                                    *
*********************************************************************/

#ifdef GEN_2D_H
#else
#define GEN_2D_H


#include "first_macro_2d.h"  /* Where global parameters are defined */
#include "structs_2d.h"      /* Where structures are defined */
#include "derivs_2d.h"       /* Where derivatives functions are defined */






struct wave_ini_par_2d {
  struct FUNCTION_PAR *function_par_ptr;
  struct GRID_PAR *grid_ptr;
/* Initial data is given by:                                    */
/*       U[0] = PHI = (a0*sin(k_a_10 x + k_a_20 y + k_a_30 z + shift_a0)   */
/*       + c_0*cos(k_c_10 x + k_c_20 y + k_c_30 z + shift_c0))*            */
/*       b_0*exp(-sigma_b0*((x-c0_1)^2+(y-c0_2)^2+(z-c0_3)^2))             */
/* U[1] = dPHI/dt = (a1*sin(k_a_11 x + k_a_21 y + k_a_31 z + shift_a1)     */
/*       + c_1*cos(k_c_11 x + k_c_21 y + k_c_31 z + shift_c1))*            */
/*       b_1*exp(-sigma_b1*((x-c1_1)^2+(y-c1_2)^2+(z-c1_3)^2))             */
/*       + v1*U[0]_x + v2*U[0]_y + v3*U[0]_z                               */

  FLOAT a0;                
  FLOAT k_a_10;            
  FLOAT k_a_20;  
  FLOAT shift_a0;         

  FLOAT a1;              
  FLOAT k_a_11;           
  FLOAT k_a_21;  
  FLOAT shift_a1;     

  FLOAT c0;             
  FLOAT k_c_10;        
  FLOAT k_c_20; 
  FLOAT shift_c0;     

  FLOAT c1;            
  FLOAT k_c_11;        
  FLOAT k_c_21;   
  FLOAT shift_c1;       
  

  FLOAT b0;           
  FLOAT sigma_b0;
  FLOAT c0_1;
  FLOAT c0_2;

  FLOAT b1;               
  FLOAT sigma_b1;
  FLOAT c1_1;
  FLOAT c1_2;

    FLOAT v1;
    FLOAT v2;
    int initial_data_type; 
};

struct wave_par_2d { 
  struct GRID_PAR *grid_ptr;

  FLOAT mm;      /* Constraint enforcing potential */
  FLOAT ee;       /* non-linearity of sigma model */
  FLOAT sigma;   /* Parameter for dissipation */
  
  FLOAT beta_sign;    /* sign of shift in foliation */
  int BETA_FORM;  /* form of shift function inside horizon */

  FLOAT R10;     /* Boundary condition at x=0, m = R0*p */
  FLOAT R11;     /* Boundary condition at x=1, p = R1*m */
  FLOAT R20;     /* Boundary condition at y=0, m = R0*p */
  FLOAT R21;     /* Boundary condition at y=1, p = R1*m */




    

  /* corners */
   FLOAT R_C_00;  /* Corner condition at x=0,y=0,z=0 */
    FLOAT R_C_01;  /* Corner condition at x=0,y=1,z=0 */
    FLOAT R_C_10;  /* Corner condition at x=1,y=0,z=0 */
    FLOAT R_C_11;  /* Corner condition at x=1,y=1,z=0 */



};





/* ---------------------------> FUNCTIONS <------------------------ */

/*********************************************************************
*                                                                    *
* inidat -- provides initial data                                    *
*                                                                    *
* Parameters:                                                        *
*       y_a_ptr -- pointer where to write the initial data          *
*                                                                    *
* Returns: nothing                                                   *
*                                                                    *
*********************************************************************/

extern void inidat(struct field_array *y_a_ptr, 
		   struct GRID_PAR *grid_ptr,
		   struct INI_PAR *ini_par_ptr
		   );


extern FLOAT theta_cub(FLOAT x, FLOAT y,int grid);

extern FLOAT phi_cub(FLOAT x, FLOAT y,int grid);

extern void Normal_cub(FLOAT x,FLOAT y,FLOAT n_x,FLOAT n_y,FLOAT n_z, int grid);


extern FLOAT Energy(struct GRID_PAR *grid_ptr,
		struct field_array *fields_ptr, 
		struct field_array *derivs_ptr,
		struct FUNCTION_PAR *function_par);
		
extern FLOAT Winding_number(struct GRID_PAR *grid_ptr,
		struct field_array *fields_ptr, 
		struct field_array *derivs_ptr,
		struct FUNCTION_PAR *function_par);
	
extern FLOAT Weight(struct GRID_PAR *grid_ptr,int i, int j);
	
extern FLOAT fz(FLOAT z);



/*********************************************************************
*                                                                    *
* integ  -- integrates dy/dt = f(y,t) between two time points        *
*                                                                    *
* Parameters:                                                        *
*   y_b_ptr     -- pointer to the initial data in field_vector struct*
*       h       -- FLOAT given the time step zice                   *
*   int_steps   -- number of steps between data savings              *
*                  (so total # of steps is data_steps x int_steps    *
*       F       -- pointer to fuction which evaluates the f(y,t)     *
*       RKX     -- pointer to runge-kutta (or any other) engine      *
*                                                                    *
* Returns: nothing                                                   *
*                                                                    *
*********************************************************************/

extern void integ(struct field_array *y_b_ptr, 
		  FLOAT h,  
		  long int int_steps, 
		  struct GRID_PAR *grid_ptr,
		  struct FUNCTION_PAR *function_par,
		  void (* FF)(FF_ARG_DUMMY), 
		  void (* RKX)(struct field_array *, 
			       FLOAT , 
			       struct GRID_PAR *,
			       struct FUNCTION_PAR *, 
			       void (* )(struct GRID_PAR *,
					 struct field_array *, 
					 struct field_array *,
					 struct FUNCTION_PAR *)
			       )
		  );

/*********************************************************************
*                                                                    *
* FF -- evaluates the function f(y,t), lots of physical imput on it  *
*                                                                    *
* Parameters:                                                        *
*       fields -- pointer to field_vector from where to extract (y,t)*
*       derivs -- pointer to field_vector where to put derivatives   *
*       function_par -- pointer to equation parameters               *
* Returns: nothing                                                   *
*                                                                    *
*********************************************************************/

extern void FF(struct GRID_PAR *grid_ptr,
	       struct field_array *fields, 
	       struct field_array *derivs, 
	       struct FUNCTION_PAR *function_par
	       );









/*********************************************************************
*                                                                    *
* adisco -- sends data to files                                      *
*                                                                    *
* Parameters:                                                        *
*       inst   -- char with instructions ("OPEN", "PUT", or "CLOSE") *
*       fields -- pointer to struct field_array with data                  *
*                                                                    *
* Returns: execution status                                          *
* Location: file adisco.c (it contains all of them)                  *
*                                                                    *
*********************************************************************/

extern FILE *adisco_graph(char inst, FILE *data[], struct GRID_PAR *gri, 
			  struct field_array *fields);
extern FILE *adisco_maple3(char inst, FILE *data[], struct GRID_PAR *gri, 
			   struct field_array *fields);
extern FILE *adisco_maple5(char inst, FILE *data[], struct GRID_PAR *gri, 
			   struct field_array *fields);     
extern FILE *adisco_mtv(char inst, FILE *data[], struct GRID_PAR *gri, 
			struct field_array *fields); 
extern FILE *adisco_idl(char inst, FILE *data[], struct GRID_PAR *gri, 
			struct field_array *fields); 
extern struct PLOT_PAR *adisco_sv(char inst,
				  struct PLOT_PAR *plot, 
				  struct GRID_PAR *gri, 
				  struct field_array *fields); 

extern struct PLOT_PAR *adisco_fsv(char inst,
				   struct PLOT_PAR *plot, 
				   struct GRID_PAR *gri, 
				   struct field_array *fields); 

extern struct PLOT_PAR *adisco_sv_2d(char inst, 
				   struct PLOT_PAR *plot_ptr, 
				   struct GRID_PAR *gri, 
				   struct field_array *fields);

extern struct PLOT_PAR *adisco_fsv_2d(char inst, 
				   struct PLOT_PAR *plot_ptr, 
				   struct GRID_PAR *gri, 
				   struct field_array *fields);

extern struct PLOT_PAR *adisco_netcdf_2d(char inst,
				   struct PLOT_PAR *plot_ptr,
				   struct GRID_PAR *gri,
				   struct field_array *fields);

extern struct PLOT_PAR *adisco_sdf_2d(char inst,
				   struct PLOT_PAR *plot_ptr,
				   struct GRID_PAR *gri,
				   struct field_array *fields);


extern struct plot_2d *get_vector_sdf_2d(int field_ind,
			     struct PLOT_PAR *plot_ptr,
			     struct GRID_PAR *grid,
			     struct field_array *fields);
			     
/*********************************************************************
*                                                                    *
* plot_prep   prepares plotting structures to be sent to files       *
*                                                                    *
*********************************************************************/


extern void plot_prep(struct PLOT_PAR *plot_ptr, 
		      struct FUNCTION_PAR *function_par, 
		      struct field_array *y_ptr
		      );

/*********************************************************************
*                                                                    *
*  rkc -- integrates    dy/dt = f(y,t)     using runge-kutta         *
*                                                                    *
* Parameters:                                                        *
*      v_init_ptr     -- pointer to where the y initial is           *
*      v_fina_ptr     -- pointer to where the y final is             *
*      h              -- time step                                   *
*      function_par   -- pointer to parameters to pass to FF         *
*      FF              -- pointer to function which computes f(y,t)  *
*                                                                    *
* Returns: nothing                                                   *
*                                                                    *
*********************************************************************/

extern void rkc(struct field_array *v_init_ptr, 
		FLOAT h,  
		struct GRID_PAR *grid_ptr,
		struct FUNCTION_PAR *function_par,
		void (* FF)(FF_ARG_DUMMY));


/* ----------------------- Asign memory to different vectors and arrays --- */

/* extern void create_field(struct field field, */
/* 			 struct grid_2d grid); */

/* extern void create_field_array(struct field_array field, */
/* 			       struct grid_2d grid); */

/* extern void create_deriv_array(struct deriv_array deriv, */
/* 			       struct grid_2d grid); */

/* extern void create_aux_array(struct aux_array aux, */
/* 			     struct grid_2d grid); */

/* extern void create_s_field_array_1(struct s_field_array_1 s_field, */
/* 				   struct grid_2d grid); */

/* extern void create_s_field_array_2(struct s_field_array_2 s_field, */
/* 				   struct grid_2d grid); */
/* extern void create_plot_field(double *plot_field, */
/* 			      struct PLOT_PAR plot); */

/* extern void free_field(struct field field, */
/* 		       struct grid_2d grid); */

/* extern void free_field_array(struct field_array field, */
/* 			     struct grid_2d grid); */

/* extern void free_deriv_array(struct deriv_array dfield, */
/* 			     struct grid_2d grid); */

/* extern void free_aux_array(struct aux_array aux_field, */
/* 			   struct grid_2d grid); */

/* extern void free_s_field_array_1(struct s_field_array_1 s_field, */
/* 				 struct grid_2d grid); */

/* extern void free_s_field_array_2(struct s_field_array_2 s_field, */
/* 				 struct grid_2d grid); */

/* extern void free_plot_array(double *plot_field, */
/* 			    struct PLOT_PAR plot); */
   

/* ----------------------- Web Data Functions ------------------------------*/
     
/****************************************************************************
 * INPUT_FUNCTION -- This function inputs data to the program which is      *
 * generated via a wave page, the input data structures are given above     *
 *                                                                          *
 ****************************************************************************/
extern  void INPUT_FUNCTION(struct GRID_PAR *grid_parameters, 
			    struct FUNCTION_PAR *function_parameters, 
			    struct INI_PAR *ini_parameters, 
			    struct PLOT_PAR *plot_parameters);



/****************************************************************************
 * Get values from an entry array and asign them to pointer given           *
 *                                                                          *
 * m -- pointer to int giving the number of entries                         *  
 * name[10] -- name of variable as given in entry                           *
 * entries  -- pointer to entry from where to obtain the pairs name/value   *
 * Return value of name                                                     *
 ***************************************************************************/

extern FLOAT get_value_double(char name[MAX_ENTRY], 
			      struct entries *entries,
			      struct PLOT_PAR *plot_par,
			      struct GRID_PAR *grid_par
			      );

extern int get_value_int(char name[MAX_ENTRY], 
			 struct entries *entries,
			 struct PLOT_PAR *plot_par,
			 struct GRID_PAR *grid_par
			 );

extern char *get_value_char(char name[MAX_ENTRY], 
			    struct entries *entries,
			    struct PLOT_PAR *plot_par,
			    struct GRID_PAR *grid_par
			    );
			    
extern FLOAT get_value_double_print(char name[MAX_ENTRY], 
			      struct entries *entries,
			      struct PLOT_PAR *plot_par,
			      struct GRID_PAR *grid_par
			      );

extern int get_value_int_print(char name[MAX_ENTRY], 
			 struct entries *entries,
			 struct PLOT_PAR *plot_par,
			 struct GRID_PAR *grid_par
			 );

extern char *get_value_char_print(char name[MAX_ENTRY], 
			    struct entries *entries,
			    struct PLOT_PAR *plot_par,
			    struct GRID_PAR *grid_par
			    );

extern void parse_stain(struct entries *entriesp);

     
extern void parse_filedata(struct entries *entriesp);


extern void    get_grid_data_2d(struct entries *entries1, 
								struct PLOT_PAR *plot_par, 
								struct GRID_PAR *grid_par
								);
								
								
extern void   get_plot_data_2d(struct entries *entries1, 
						struct PLOT_PAR *plot_par, 
						struct GRID_PAR *grid_par);

/****************************************************************************
 * This are utilities functions to handle data given via web                *
 *                                                                          *
 ****************************************************************************/
extern  char *makeword(char *line, char stop);
extern  char *fmakeword(FILE *f, char stop, int *len);
extern  char x2c(char *what);
extern  void unescape_url(char *url);
extern  void plustospace(char *str);


/*************************************************************************/

/**********************   Global variables  ******************************/


/* ---------------------------  rkc -------------------------------------*/

extern struct field_array dv_temp;        /* derivative temporal value         */
extern struct field_array dv_sum;         /* sum values of deriv               */
extern struct field_array v_temp;         /* intermediate value of v           */


extern struct field_array *dv_temp_ptr;        /* derivative temporal value        */
extern struct field_array *dv_sum_ptr;         /* sum          values of deriv     */
extern struct field_array *v_temp_ptr;         /* intermediate value of v          */


/* ---------------------------- FF --------------------------------------*/
    
               /* temporal space derivative values */

extern struct deriv_array dfields;     
extern struct aux_array auxfields;
extern struct s_field_array sfield_recv;
extern struct s_field_array sfield_send;
extern MPI_Comm global;

/********************************************************************/

#endif
